#!/bin/bash

flink=/opt/module/flink-yarn/bin/flink
realtime_jar=/opt/module/gmall210422/gmall-realtime-1.0-SNAPSHOT.jar
apps=(
com.atguigu.gmall.realtime.app.dwd.DwdLogApp
)
# 遍历数据, 每个app都启动

# 找到所有已经运行的app
running_apps=`${flink} list -r 2>/dev/null | awk '/RUNNING/ {print \$(NF-1)}'`


for app in ${apps[*]} ; do
    # 判断app是否已经存在于running_apps中
    job_name=`echo ${app} | awk -F. '{print \$NF}'`
    
    if [[ "${running_apps[@]}" =~ $job_name ]]; then
        echo "$job_name 已经启动无需重复启动"
    else
        echo "开始启动 $job_name"
        ${flink} run -d -c ${app} ${realtime_jar}
    fi
done




